package org.xhs.geomap.net
{
	import com.mapabc.maps.api.basetypes.MLngLat;
	
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	public class BuildingXMLParser
	{
		private var loader:URLLoader;
		private var xml:XML;
		private var buildingArray:Array = new Array();
		
		public function BuildingXMLParser()
		{
		}
		
		public function parse(url:String):Array
		{
			var urlrequest:URLRequest = new URLRequest(url);
			loader = new URLLoader(urlrequest);
			loader.addEventListener(Event.COMPLETE, loadcomplete);
			return buildingArray;
		}
		
		public function loadcomplete(eve:Event):void
		{
			xml = new XML(loader.data);
			for(var i:Number = 0;i < xml.building.length();i++)
			{
				var building:Object = new Object();
				building.id = xml.building[i].@id;
				building.name = xml.building[i].@bname;
				building.lnglat = new MLngLat(xml.building[i].@lng, xml.building[i].@lat);
				buildingArray.push(building);
			}
		}
	}
}